﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccessLayer;
using BussinessLayer;

namespace QLBaoHanh.QLTbiDangONCC
{
    public partial class frmNhanVeTuNCC : Form
    {
        private int _phien_ThietBiBH;
        private string _maThietBiBH;
        private frmDsTbiDangONCC _callerForm;


        public frmNhanVeTuNCC(int inPhien_ThietBiBH, string inMaThietBiBH, frmDsTbiDangONCC inCallerForm)
        {
            InitializeComponent();
            cboTinhTrang.SelectedIndex = 0;
            _phien_ThietBiBH = inPhien_ThietBiBH;
            _maThietBiBH = inMaThietBiBH;
            groupBox1.Text = "Thiết bị: " + _maThietBiBH;
            _callerForm = inCallerForm;
        }

        private void btnFinish_Click(object sender, EventArgs e)
        {
            MyCommon.TrangThaiThietBiBH SuaDuoc = MyCommon.TrangThaiThietBiBH.DaNhanVeChuaHoanThanh;
            if (cboTinhTrang.SelectedIndex == 0)
            {
                //Sua duoc
                SuaDuoc = MyCommon.TrangThaiThietBiBH.ChoTra;
            }
            //Thay doi trang thai va thoi diem hoan thanh
            Phien_ThietBiBH obj = Phien_ThietBiBHBO.getInstance.GetPhien_ThietBiBHById(_phien_ThietBiBH);
            obj.TrangThaiThietBiBHID = (int)SuaDuoc;
            obj.ThoiDiemHoanThanh = DateTime.Now;
            obj.GhiChuHoanThanh = txtGhiChu.Text;
            Phien_ThietBiBHBO.getInstance.UpdatePhien_ThietBiBH(obj);
            //Luu lai lich su bao hanh
            LichSuBH LichSu = new LichSuBH();
            LichSu.LoaiLichSu = (int)MyCommon.LoaiLichSu.LichSuHeThong;
            LichSu.Phien_ThietBiBHId = _phien_ThietBiBH;
            LichSu.ThoiGian = DateTime.Now;
            LichSu.NVThucHienId = frmMain.CurrentNhanVien.Id;
            LichSu.NoiDung = cboTinhTrang.SelectedItem.ToString() + "--- GhiChu: " + txtGhiChu.Text;
            LichSuBHBO.getInstance.InsertLichSuBH(LichSu);
            _callerForm.RefreshForm();
            this.Close();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
